#ifndef __CONVEX_HULL_CREATOR_CANVAS_HPP__
#define __CONVEX_HULL_CREATOR_CANVAS_HPP__

////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <vector>

#include <SFML/Graphics/VertexArray.hpp>
#include <SFML/System/Vector2.hpp>

#include "wxSFMLCanvas.hpp"
#include "SmegPlaceable.hpp"

namespace smeg {
    class PlaceableObject;
    namespace light {
        class LightSystem;
    }
}

////////////////////////////////////////////////////////////
/// ConvexHullCreatorCanvas is a specialized class of wxSFMLCanvas
////////////////////////////////////////////////////////////
class ConvexHullCreatorCanvas :
    public wxSFMLCanvas
{
public:
    ////////////////////////////////////////////////////////////
    /// Construct the ConvexHullCreatorCanvas
    ///
    /// \param Parent :   Parent of the control (NULL by default)
    /// \param Id :       Identifier of the control (-1 by default)
    /// \param Position : Position of the control (wxDefaultPosition by default)
    /// \param Size :     Size of the control (wxDefaultSize by default)
    /// \param Style :    Style of the control (0 by default)
    ///
    ////////////////////////////////////////////////////////////
    ConvexHullCreatorCanvas(wxWindow*      Parent       = NULL, 
                            wxWindowID      Id          = -1, 
                            const wxPoint&  Position    = wxDefaultPosition, 
                            const wxSize&   Size        = wxDefaultSize, 
                            long            Style       = 0);
    
    ////////////////////////////////////////////////////////////
    /// Destructor
    ///
    ////////////////////////////////////////////////////////////
    virtual ~ConvexHullCreatorCanvas();
    
    ////////////////////////////////////////////////////////////
    /// Update a vertex position
    ///
    /// \param _numVertex :     Vertex to update
    /// \param _x :             New X value
    /// \param _y :             New Y value
    ///
    ////////////////////////////////////////////////////////////
    void UpdateVertexPosition( unsigned _numVertex, float _x, float _y );
    
    ////////////////////////////////////////////////////////////
    /// Resize the vertex array
    ///
    /// \param _numVertices :   New number of vertices
    ///
    ////////////////////////////////////////////////////////////
    void Resize( int _numVertices );
    
    ////////////////////////////////////////////////////////////
    /// Get the vertex Array
    ///
    /// \return the vertex array
    ///
    ////////////////////////////////////////////////////////////
    const sf::VertexArray& GetVertexArray() const;

private :    
    ////////////////////////////////////////////////////////////
    /// Notification for the derived class that moment is good
    /// for doing its update and drawing stuff
    ///
    ////////////////////////////////////////////////////////////
    virtual void OnUpdate();
    
    ////////////////////////////////////////////////////////////
    /// Events
    ///
    ////////////////////////////////////////////////////////////
    void OnMouseLeftDown( wxMouseEvent& event );
    void OnMouseLeftUp( wxMouseEvent& event );
    void OnMouseMove( wxMouseEvent& event );

    sf::VertexArray             m_vertexArray;

    int                         m_iNumVertexSelected;
    SmegPlaceable*              m_pPlaceableDragged;
    std::vector<SmegPlaceable>  m_verticesPlaceable;
};
    
////////////////////////////////////////////////////////////
/// Get the vertex Array
////////////////////////////////////////////////////////////
inline const sf::VertexArray& ConvexHullCreatorCanvas::GetVertexArray() const {
    return m_vertexArray;
}

#endif // __CONVEX_HULL_CREATOR_CANVAS_HPP__
